<?php
/**
 * 网络请求
 * @author  wyb <[<email address>]>
 */
namespace Api\Server;
class HttpServer {

	public static $_self = null;

	/**
	 * 初始化类
	 */
	public static function init() {
		return self::$_self == null ? new self() : self::$_self;
	}

	/**
	 * curl请求
	 */
	public function send( $url , $data , $header = '' ) {
		$ci = curl_init();
		curl_setopt( $ci, CURLOPT_URL, $url );
		curl_setopt( $ci, CURLOPT_RETURNTRANSFER, true);
		if( $header ) {
			curl_setopt( $ci, CURLOPT_HTTPHEADER, $header);
		}
		//array( "Content-type: text/xml" )
		curl_setopt( $ci, CURLOPT_SSL_VERIFYPEER, FALSE); 
		curl_setopt( $ci, CURLOPT_SSL_VERIFYHOST, FALSE);
		curl_setopt( $ci, CURLOPT_POST, 1);
		curl_setopt( $ci, CURLOPT_POSTFIELDS,  $data );
		if( curl_errno( $ci ) ){
			print curl_error($ci);
		}
		
		$result = curl_exec( $ci );
		$status = curl_getinfo( $ci );
		curl_close($ci);
		return array( 'result' => $result , 'status' => $status );
	}
}